<style>
  #bookSell-add {
    padding: 20px 25px 25px 0;
  }

  #bookSell-add .layui-treeSelect .ztree li a, .ztree li span {
    margin: 0 0 2px 3px !important;
  }
</style>
<div class="layui-fluid" id="bookSell-add">
  <form class="layui-form" action="" lay-filter="bookSell-add-form">
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">图书名称：</label>
      <div class="layui-input-block">
        <select name="bookname"
                lay-verify="required"
                xm-select-direction="down"
                xm-select="insure-bookname"
                xm-select-skin="default">
        </select>
      </div>
    </div>
    <div class="layui-form-item febs-hide">
      <button class="layui-btn" lay-submit="" lay-filter="bookSell-add-form-submit" id="submit"></button>
      <button type="reset" class="layui-btn" id="reset"></button>
    </div>
  </form>
</div>

<script>
  layui.use(['febs', 'form', 'validate', 'formSelects', 'jquery'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#bookSell-add'),
        formSelects = layui.formSelects,
        $searchForm = $view.find('form'),
        validate = layui.validate;

    form.verify(validate);
    form.render();

    formSelects.render();
    formSelects.config('insure-bookname', {
      searchUrl: ctx + 'warehouseBook?intoware=1&putaway=0',
      response: {
        statusCode: 200
      },
      beforeSuccess: function (id, url, searchVal, result) {
        console.log(result);
        var data = result.data;
        var tranData = [];
        for (var i = 0; i < data.length; i++) {
          tranData.push({
            name: data[i].bookname,
            value: data[i].bookname
          })
        }
        result.data = tranData;
        return result;
      },
      error: function (id, url, searchVal, err) {
        console.error(err);
        febs.alert.error('图书加载失败');
      }
    });

    form.on('submit(bookSell-add-form-submit)', function () {
      febs.post(ctx + 'bookSell/' + $searchForm.find('input[name="bookname"]').val().trim(), null, function () {
        layer.closeAll();
        febs.alert.success('申请上架发送成功');
        $('#febs-bookSell').find('#query').click();
      });
      return false;
    });
  });
</script>